<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('component_types', function (Blueprint $table) {
            $table->id();
            $table->foreignId('component_id')->constrained()->onDelete('cascade');
            $table->string('framework')->comment('vuejs, reactjs, html, blade, uniapp, nextjs, nuxtjs etc');
            $table->longText('code')->comment('usually HTML code for blade, the component code, vuejs, react js etc');
            $table->longText('js')->nullable()->comment('vanilla javascript code for blade');
            $table->longText('css')->nullable()->comment('additional css code for blade');
            $table->json('included_component_type_ids')->nullable();
            $table->json('dependencies')->nullable()->comment('npm dependencies');
            $table->json('params')->nullable();
            $table->timestamps();
        });

        DB::table('component_types')->insert([
            [
                'component_id' => 1,
                'framework' => 'vue',
                'code' => '// your vuejs component code here',
                'included_component_type_ids' => json_encode([4, 5]),
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'component_id' => 1,
                'framework' => 'react',
                'code' => '// your reactjs component code here',
                'included_component_type_ids' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'component_id' => 1,
                'framework' => 'blade',
                'code' => '// your reactjs component code here',
                'included_component_type_ids' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'component_id' => 2,
                'framework' => 'vue',
                'code' => '// your reactjs component code here',
                'included_component_type_ids' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'component_id' => 3,
                'framework' => 'vue',
                'code' => '// your reactjs component code here',
                'included_component_type_ids' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('component_types');
    }
};
